//
//  UIViewController+Sheet.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/20.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "UIViewController+Sheet.h"

@implementation UIViewController (Sheet)

- (void)showSheetWithTitle:(NSString *)title message:(NSString *)message acitons:(NSArray <NSString *>*)acitons callBack:(void(^)(NSInteger index))block
{
    UIAlertController *sheet = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    
    for (NSString *title in acitons)
    {
        UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (block)
            {
                block([acitons indexOfObject:title]);
            }
        }];
        [sheet addAction:action];
    }
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        if (block)
        {
            block(-1);
        }
    }];
    [sheet addAction:action];
    
    [self presentViewController:sheet animated:YES completion:^{
        
    }];
}

@end
